package com.yl.auth.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.model.entity.Gangwei;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 
 * @since 2023-06-15
 */
public interface GangweiMapper extends BaseMapper<Gangwei> {

    @Insert("insert into gangwei(name,creator_id,create_time) values(#{g.name},#{g.creatorId},now())")
    boolean saveGangwei(@Param("g") Gangwei gangwei);

    @Select("select a.*,COUNT(yuangongid) num from gangwei a LEFT JOIN yuangong_gangwei b on a.id=b.gangweiid  GROUP BY a.id order by a.create_time desc")
    IPage<Gangwei> getAll(Page<Gangwei> page);

    @Delete("DELETE from role_permission where role_id=#{id}")
    void deleteQuanXian(Integer id);

    @Insert("INSERT INTO role_permission(role_id,permission_id) VALUES(#{id},#{quanxianid})")
    void addQuanXian(@Param("id") Integer id, @Param("quanxianid") Integer quanxianid);

    @Select("SELECT permission_id from role_permission where role_id=#{id}")
    List<Integer> getQuanXianById(@Param("id") Long id);
}
